package com.cskaoyan.controller.admincontroller;

import com.cskaoyan.bean.po.MarketGoods;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.chaosbean.goods.bo.UpdatePO;
import com.cskaoyan.bean.chaosbean.goods.vo.CatAndBrandVO;
import com.cskaoyan.bean.chaosbean.goods.vo.Detail;
import com.cskaoyan.service.adminservice.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author dengqwe
 * @datetime 2022/12/28 19:52
 * @description: TODO:
 */
@RestController
@RequestMapping("admin/goods")
public class GoodsController {

    @Autowired
    GoodService goodService;

    @RequestMapping("list")
    //page=1&limit=20&sort=add_time&order=desc
    //public BaseRespVo list(Integer page,Integer limit,String sort,String order){
    public BaseRespVo list(BasePageInfo basePageInfo, Integer goodsId, String goodsSn, String name) {
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        CommonData<MarketGoods> data = goodService.list(basePageInfo, goodsId, goodsSn, name);
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(data);
        return baseRespVo;
    }

    @RequestMapping(value = "create", method = RequestMethod.POST)
    public BaseRespVo create(@RequestBody UpdatePO create) {
        goodService.create(create);
        return BaseRespVo.ok();
    }

    @RequestMapping("catAndBrand")
    public BaseRespVo catAndBrand() {
        CatAndBrandVO catAndBrandVO = goodService.catAndBrand();
        return BaseRespVo.okYa(catAndBrandVO);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(String id) {
        Detail detail = goodService.detail(id);
        return BaseRespVo.okYa(detail);
    }
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MarketGoods good){
        goodService.delete(good);
        return BaseRespVo.ok();
    }
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public BaseRespVo update(@RequestBody UpdatePO update){
        goodService.update(update);
        return BaseRespVo.ok();
    }
}
